/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Excersize2_Swing;

import javax.swing.JPanel;
import battleshipgame.logic.Constants;
import Excersize2_Swing.BattleshipGameJFrame;
import battleshipgame.logic.Board;
import battleshipgame.logic.Coordinate;
import battleshipgame.logic.Player;

import java.awt.*;
import javax.swing.*;

/**
 *
 * @author אלירן
 */
public class SubmarineBoardPanel extends JPanel {

    private int BOARD_SIZE = Constants.BOARD_SIZE;
    BattleshipGameJFrame referBattleshipGameJFrame;

    //BattleshipGameJFrame refference; 
    public SubmarineBoardPanel(BattleshipGameJFrame referBattleshipGameJFrame, Player player) {
        GridLayout gridBoard = new GridLayout(BOARD_SIZE, BOARD_SIZE);
        Board board = player.getBoard();
        this.setLayout(gridBoard);
        this.repaint();
        this.referBattleshipGameJFrame = referBattleshipGameJFrame;
        //this.setSize(400, 400);
        //this.refference = refference ;
        for (int row = 0; row < BOARD_SIZE; row++) {
            for (int col = 0; col < BOARD_SIZE; col++) {
                addSquareButtonToPanel(col, row, this, board);
            }
        }
        this.setVisible(true);
        this.repaint();
    }
    public void addSquareButtonToPanel(int x, int y, JPanel panel, Board board) {
        //TODO fill this
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        String coordinate = TurnCoordinateToString(x, y);
        panel.add(new SquareButton(coordinate,
                board.getSquareByCoordinate(new Coordinate(x, y)), referBattleshipGameJFrame));
    }

    public static String TurnCoordinateToString(int x, int y) {
        String coordinate;
        char cx = (char) ('A' + x);
        if (y <= 9) {
            coordinate = cx + "" + (y + 1);
        } else {
            coordinate = cx + "10";
        }
        return coordinate;
    }

    public static void main() {
    }
}//end of class

